import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class PPMessageItemView extends StatefulWidget {

	PPMessageItemView({Key key, this.data, this.action}) : super(key: key);

	final Map data;
	final Function action;

	_PPMessageItemState createState() => _PPMessageItemState();
}

class _PPMessageItemState extends State<PPMessageItemView> {
	
	@override
	Widget build(BuildContext context) {
		String title = widget.data['title'];
		String time = widget.data['time'];
		String desc = widget.data['desc'];
		String num = widget.data['num'];

		return (FlatButton(
			padding: EdgeInsets.all(0),
			child: Container(
				color: Colors.white,
				padding: EdgeInsets.fromLTRB(15, 15, 15, 0),
				child: Container(
					padding: EdgeInsets.only(bottom: 15),
					decoration: BoxDecoration(
					border: Border(bottom: BorderSide(color: Color.fromRGBO(238,238,238,1),  width: 1.0, style: BorderStyle.solid))
					),
					child: Column(
						mainAxisAlignment: MainAxisAlignment.start,
						children: [
							Row(
								mainAxisAlignment: MainAxisAlignment.spaceBetween,
								verticalDirection: VerticalDirection.down,
								children: [
									Text(title, style: TextStyle(fontSize: 13, color: Color.fromRGBO(51, 51, 51, 1))),
									Text(time, style: TextStyle(fontSize: 10, color: Color.fromRGBO(102, 102, 102, 1)))
								],
							),
							Container(
								margin: EdgeInsets.only(top: 10),
								child: Row(
									mainAxisAlignment: MainAxisAlignment.spaceBetween,
									verticalDirection: VerticalDirection.down,
									children: [
										Text(desc, style: TextStyle(fontSize: 12, color: Color.fromRGBO(102, 102, 102, 1))),
										Container(
											width: 18,
											height: 18,
											alignment: Alignment.center,
											decoration: BoxDecoration( borderRadius: BorderRadius.circular(9), color: Colors.red),
											child: Text(num, style: TextStyle(fontSize: 9, color: Colors.white)),
										)
									],
								)
							)			
						],
					)
				),
			),
			onPressed: _onClickMessageItemAction,
		));
	}

	_onClickMessageItemAction() {
		if(widget.action != null) {
			widget.action(widget.data);
		}
	}
}
